﻿using System;

using FakeItEasy;

using NewModel.Accounting.Calculation;
using NewModel.Accounting.Core;
using NewModel.Accounting.Persistence;
using NewModel.UnitTests.Accounting.Persistence._Samples_;

using NUnit.Framework;

namespace NewModel.UnitTests.Accounting.Persistence
{
    [TestFixture]
    public sealed class TestLedgerOperations
    {
        LedgerOperations2 mUnderTest;
        IBatchesOperations mBatchesOperations;
        ITransactionRegistrant mTransactionRegistrant;
        static readonly Transaction sExpenseTransaction = Sample.ExpenseTransaction;
        static readonly DateTime sExpenseTransactionTimestamp = sExpenseTransaction.Timestamp;
        static readonly Batch[] sBatches = new Batch[0];

        [SetUp]
        public void SetUp()
        {
            mBatchesOperations = A.Fake<IBatchesOperations>();
            mTransactionRegistrant = A.Fake<ITransactionRegistrant>();
            mUnderTest = new LedgerOperations2(mBatchesOperations, mTransactionRegistrant);
        }


        [Test]
        public void RegisterTransaction_Should_GetBatchesChain_And_AddTransaction_To_It()
        {
            A.CallTo(() => mBatchesOperations.GetBatchesChain(sExpenseTransactionTimestamp))
                .Returns(sBatches);
            mUnderTest.RegisterTransaction(sExpenseTransaction);
            A.CallTo(() => mTransactionRegistrant.AddTransaction(sBatches, sExpenseTransaction))
                .MustHaveHappened();
        }
    }
}